package com.cn.wanxi.dao.impl;

import com.cn.wanxi.dao.ICompanyDao;
import com.cn.wanxi.model.CompanyModel;
import com.cn.wanxi.util.GetSqlSession;
import com.cn.wanxi.util.JDBC;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class CompanyDaoImpl implements ICompanyDao {
    JDBC jdbc=new JDBC();
    @Override
    public CompanyModel findAll() {
        return GetSqlSession.getSqlSession().selectOne("com.cn.wanxi.dao.ICompanyDao.findAll");
//        String sql="SELECT * FROM company";
//        ResultSet resultSet=jdbc.getResultSet(sql);
//        CompanyModel companyModel=new CompanyModel();
//        try {
//            while (resultSet.next()){
//                companyModel.setId(resultSet.getInt("id"));
//                companyModel.setLogo(resultSet.getString("logo"));
//                companyModel.setEmail(resultSet.getString("email"));
//                companyModel.setHotline(resultSet.getString("hotline"));
//                companyModel.setAddress(resultSet.getString("address"));
//                companyModel.setPhone(resultSet.getString("phone"));
//                companyModel.setTel(resultSet.getString("tel"));
//                companyModel.setLandline(resultSet.getString("landline"));
//            }
//        } catch (SQLException e) {
//            e.printStackTrace();
//        }
//        return companyModel;
    }

    @Override
    public CompanyModel findById(int companyid) {
        return GetSqlSession.getSqlSession().selectOne("com.cn.wanxi.dao.ICompanyDao.findById",companyid);
//        String sql="SELECT * FROM company where id = '"+companyid+"'";
//        ResultSet resultSet=jdbc.getResultSet(sql);
//        CompanyModel companyModel=new CompanyModel();
//        try {
//            while (resultSet.next()){
//                companyModel.setId(resultSet.getInt("id"));
//                companyModel.setLogo(resultSet.getString("logo"));
//                companyModel.setEmail(resultSet.getString("email"));
//                companyModel.setHotline(resultSet.getString("hotline"));
//                companyModel.setAddress(resultSet.getString("address"));
//                companyModel.setPhone(resultSet.getString("phone"));
//                companyModel.setTel(resultSet.getString("tel"));
//                companyModel.setLandline(resultSet.getString("landline"));
//            }
//        } catch (SQLException e) {
//            e.printStackTrace();
//        }
//        jdbc.closeConn();
//        return companyModel;
    }

    @Override
    public int update(CompanyModel companyModel) {
        return GetSqlSession.getSqlSession().update("com.cn.wanxi.dao.ICompanyDao.update",companyModel);
//        String sql="update company set logo='"+companyModel.getLogo()+"'" +
//                " ,email='"+companyModel.getEmail()+"'" +
//                " ,hotline='"+companyModel.getHotline()+"'" +
//                " ,address='"+companyModel.getAddress()+"'" +
//                " ,phone='"+companyModel.getPhone()+"'" +
//                " ,tel='"+companyModel.getTel()+"'" +
//                " ,landline='"+companyModel.getLandline()+"'";
//        int resultSet = jdbc.update(sql);
//        jdbc.closeConn();
//        return resultSet;
    }

//    @Override
//    public CompanyModel getCompanyModel() {
//        String sql="SELECT * FROM company";
//        ResultSet resultSet=jdbc.getResultSet(sql);
//        CompanyModel companyModel=new CompanyModel();
//        try {
//            while (resultSet.next()){
//                companyModel.setId(resultSet.getInt("id"));
//                companyModel.setLogo(resultSet.getString("logo"));
//                companyModel.setEmail(resultSet.getString("email"));
//                companyModel.setHotline(resultSet.getString("hotline"));
//                companyModel.setAddress(resultSet.getString("address"));
//                companyModel.setPhone(resultSet.getString("phone"));
//                companyModel.setTel(resultSet.getString("tel"));
//                companyModel.setLandline(resultSet.getString("landline"));
//            }
//        } catch (SQLException e) {
//            e.printStackTrace();
//        }
//        return companyModel;
//    }
}
